public class 最长公共前缀 {
    
    public static void main(String[] args) {
        

    }

    public static String longestCommonPrefix(String[] strs) {
        
        if(null == strs || strs.length < 1) return "";
        //默认一个字符串为前缀
        String prefix = strs[0];

        for(int i=0; i<strs.length; i++){

            while (strs[i].indexOf(prefix) !=0) {
                
                prefix = prefix.substring(0, prefix.length() -1 );


                if(prefix.isEmpty()){

                    return "";
                }

            }

        }


        return prefix;
    }
}
